﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kiiro.Common.Interfaces;

namespace Kiiro.Common.Entities
{
    [Serializable]
    public class Discussion : BaseEntity, IEntity
    {
        #region Private Properties

        private string text;
        private List<ValidationMessage> textMessage = new List<ValidationMessage>();
        private string htmlText;
        private List<ValidationMessage> htmlTextMessage = new List<ValidationMessage>();
        private int numberOfComments;
        private List<ValidationMessage> numberOfCommentsMessage = new List<ValidationMessage>();
        private List<Comment> comments = new List<Comment>();
        private List<ValidationMessage> commentsMessage = new List<ValidationMessage>();
        private List<int> usersToNotify = new List<int>();
        private List<ValidationMessage> usersToNotifyMessage = new List<ValidationMessage>();
        private DateTime lastCommentDate;
        private List<ValidationMessage> lastCommentDateMessage = new List<ValidationMessage>();

        #endregion

        #region Public Properties

        public string Text
        {
            get { return text; }
            set
            {
                if (text != value)
                {
                    text = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> TextMessage
        {
            get { return textMessage; }
            set
            {
                if (textMessage != value)
                {
                    textMessage = value;
                    UpdateEntity();
                }
            }
        }

        public string HTMLText
        {
            get { return htmlText; }
            set
            {
                if (htmlText != value)
                {
                    htmlText = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> HTMLTextMessage
        {
            get { return htmlTextMessage; }
            set
            {
                if (htmlTextMessage != value)
                {
                    htmlTextMessage = value;
                    UpdateEntity();
                }
            }
        }

        public int NumberOfComments
        {
            get { return numberOfComments; }
            set
            {
                if (numberOfComments != value)
                {
                    numberOfComments = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> NumberOfCommentsMessage
        {
            get { return numberOfCommentsMessage; }
            set
            {
                if (numberOfCommentsMessage != value)
                {
                    numberOfCommentsMessage = value;
                    UpdateEntity();
                }
            }
        }

        public List<Comment> Comments
        {
            get { return comments; }
            set
            {
                if (comments != value)
                {
                    comments = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> CommentsMessage
        {
            get { return commentsMessage; }
            set
            {
                if (commentsMessage != value)
                {
                    commentsMessage = value;
                    UpdateEntity();
                }
            }
        }

        public List<int> UsersToNotify
        {
            get { return usersToNotify; }
            set
            {
                if (usersToNotify != value)
                {
                    usersToNotify = value;
                    UpdateEntity();
                }
            }
        }

        public List<ValidationMessage> UsersToNotifyMessage
        {
            get { return usersToNotifyMessage; }
            set
            {
                if (usersToNotifyMessage != value)
                {
                    usersToNotifyMessage = value;
                    UpdateEntity();
                }
            }
        }
        
        public DateTime LastCommentDate
        {
            get { return lastCommentDate; }
            set { lastCommentDate = value; }
        }

        public List<ValidationMessage> LastCommentDateMessage
        {
            get { return lastCommentDateMessage; }
            set { lastCommentDateMessage = value; }
        }

        #endregion

        #region IEntity Members


        public new bool IsValid()
        {
            return AllValidationErrors().Count == 0;
        }

        public new List<ValidationMessage> AllValidationErrors()
        {
            List<ValidationMessage> allErrors = new List<ValidationMessage>();

            allErrors.AddRange ( TitleMessage );
            allErrors.AddRange(TextMessage);
            allErrors.AddRange(HTMLTextMessage);
            allErrors.AddRange(NumberOfCommentsMessage);
            allErrors.AddRange(CommentsMessage);
            allErrors.AddRange(UsersToNotifyMessage);
            allErrors.AddRange(AttachmentListMessage);

            return allErrors;
        }

        public new void ClearValidationMessages()
        {
            TitleMessage.Clear ( );
            TextMessage.Clear();
            htmlTextMessage.Clear();
            NumberOfCommentsMessage.Clear();
            CommentsMessage.Clear();
            UsersToNotifyMessage.Clear();
            AttachmentListMessage.Clear();
        }

        #endregion
    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.Common/Entities/Discussion.cs $
 * 
 * 5     12/14/09 2:10p Shafia
 * attachments file extensions validation for discussions, tasks, and
 * issues
 * 
 * 4     24/11/09 10:55a Shafia
 * Discussion now stores the HTML format of the discussion text and uses
 * the WMD editor
 * 
 * 3     17/08/09 10:38a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/